package com.example.imtoken.view

import android.content.Context
import android.widget.TextView
import com.blankj.utilcode.util.NumberUtils
import com.example.imtoken.R
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.CandleEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF

class MyMarkerView(mContext: Context, layoutResource: Int) : MarkerView(mContext, layoutResource) {

    private val tvMarker: TextView = findViewById(R.id.tvMarker)

    override fun refreshContent(e: Entry?, highlight: Highlight?) {
        if (e is CandleEntry) {
            tvMarker.text = NumberUtils.format(e.high, 2)
//            tvMarker.text = Utils.formatNumber(e.high, 2, false)
        } else {
            tvMarker.text = NumberUtils.format(e?.y ?: 0F, 2)
//            tvMarker.text = Utils.formatNumber(e?.y ?: 0F, 2, false)
        }
        super.refreshContent(e, highlight)
    }

    override fun getOffset(): MPPointF {
        return MPPointF((-(width / 2)).toFloat(), -height.toFloat())
    }

}